//
//  NewPhoneNumViewController.m
//  ZhiBoYuan
//
//  Created by coder_di on 2018/4/18.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "NewPhoneNumViewController.h"
#import "TianXieYanZhengmaViewController.h"

@interface NewPhoneNumViewController ()

@property (nonatomic, strong)UITextField *phoneNumTextField;

@end

@implementation NewPhoneNumViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = hui1Color;
    self.title = @"新手机号";
    
    [self setUI];
}


-(void)setUI{
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(20 * KscreenWidth, 30 * KscreenHeight + NAVIGATION_BAR_HEIGHT, ScreenWidth - 40 * KscreenWidth, 20 * KscreenHeight)];
    lable.text = @"更换手机号后，将以新的手机号登录此账号";
    lable.font = [UIFont systemFontOfSize:18 *KscreenWidth];
    lable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:lable];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 80 * KscreenHeight + NAVIGATION_BAR_HEIGHT, ScreenWidth, 50 * KscreenHeight)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    _phoneNumTextField = [[UITextField alloc]initWithFrame:CGRectMake(20 * KscreenWidth, 15 * KscreenHeight, ScreenWidth - 40 * KscreenWidth, 20 * KscreenHeight)];
    _phoneNumTextField.placeholder = @"请输入新手机号";
    _phoneNumTextField.font = [UIFont systemFontOfSize:18 * KscreenWidth];
    [view addSubview:_phoneNumTextField];
    
    UIButton *nextBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    nextBtn.frame  = CGRectMake(20 * KscreenWidth, 250 * KscreenHeight, ScreenWidth - 40 * KscreenWidth, 50 * KscreenHeight );
    nextBtn.layer.masksToBounds = YES;
    nextBtn.layer.cornerRadius = 5 * KscreenWidth;
    nextBtn.backgroundColor = ZhuTiColor;
    [nextBtn setTitle:@"下一步" forState:0];
    [nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:nextBtn];
    
}

-(void)nextBtnAction{
    if (_phoneNumTextField.text.length == 11) {
        
        NSString *str = [NSString stringWithFormat:@"我们将发送验证码短信到这个号码%@",_phoneNumTextField.text];
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确认手机号码" message:str preferredStyle:UIAlertControllerStyleAlert];
        
        [_phoneNumTextField resignFirstResponder];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            TianXieYanZhengmaViewController *xiugaiVC = [[TianXieYanZhengmaViewController alloc]init];
            xiugaiVC.xindePhone = _phoneNumTextField.text;
            xiugaiVC.oldYanZhengMa = _honeCode;
            [self.navigationController pushViewController:xiugaiVC animated:YES];
        }];
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@" 取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            return ;
        }];
        
        [alertController addAction:cancelAction];
        
        [alertController addAction:okAction];
        
        [self presentViewController:alertController animated:YES completion:nil];

    }else{
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"请输入正确的手机号" message:@"" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil, nil];
        [alertView show];
    }
    
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [_phoneNumTextField resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
